Hey there.
In this lecture I want to go over the comparison operators in Lua.
You already know three comparison operators greater than, less than and equal to.
But there are three other comparison operators I would like to demonstrate.
So I'm going to open up this little section here in my script.
And here are the six comparison operators we get to use in Lua.
You already know of the less than, greater than and equal to comparison operators, but we have a few
others, such as less than or equal to, greater than or equal to and not equal to, and we use a tilde
key to represent not equal.
So to demonstrate this all I'm going to do is create a variable.
I'm just going to call it comparison num.
And we're going to set it equal to a value of like ten.
Then we can create an if statement.
So we'll type out if and then create our condition here.
So we're going to check if our comparison number is let's say less than 50.
So if our comparison number is less than 50 then we can print out into the console.
The condition was truthy.
And obviously since ten is less than 50 we should get that string printed into the console.
So we hit run.
There we go.
The condition was truthy.
However, once comparison number becomes greater than 50 and we hit run.
As you can see, nothing gets printed out into the console because that condition evaluated to false.
However, let's say the comparison number was exactly the value of 50.
Well, 50 is not less than 50, so this condition would still evaluate to false.
But what if we wanted to include the value of 50?
Well this is where we can use the less than or equal to comparison operator.
So what I'm going to do is put an equal sign here and there we go.
Now it's checking if the comparison number is less than or equal to the value of 50.
And since 50 is equal to 50 this should be true.
We hit run and there we go.
The condition was truthy.
We can also check if comparison number is greater than or equal to 50.
So if we made this value such as 51 and we hit run, of course the condition was truthy because 51 is
greater than 50 and if we left it at 50 it would also evaluate to true because 50 is equal to 50.
Now what if we want to check when a value is not equal to another specific value?
For example, maybe we only want to execute this if statement when comparison number is not equal to
ten.
So if I put this tilde key here, we're now checking if comparison number is not equal to.
And then we can put the value of ten here.
So this will only execute when comparison number is not equal to ten.
Any time the comparison number is ten this is not going to execute.
So if I put the value of ten here and we go and run.
As you can see, nothing gets printed in the console because ten is equal to ten.
So this evaluated to false.
But if we made comparison number for example like negative ten and we hit run.
As you can see, the condition was truthy because negative ten is not equal to ten.
We can also make this a big number like like that.
And then we hit run.
And of course the condition was truthy because that big number is not equal to ten.
So this was just a brief overview of the comparison operators you will be using in the conditions for
your if statements.
I will see you in the next one.